package StringDemo.demo1;

import java.util.Scanner;

public class UserLogin {
    public static void main(String[] args) {
        String rightUsername = "xixialiusuyue";
        String rightPassword = "123456";
        for (int i = 0; i < 3; i++) {
            //需要把用户输入循环里面才能保证每次循环都能输入
            //想要循环的变量都要放在循环里面
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入姓名");
            String username = sc.nextLine();
            System.out.println("请输入密码");
            String password = sc.nextLine();
            if (username.equals(rightUsername) && password.equals(rightPassword)) {
                System.out.println("登陆成功");
                break;
            }else {
                if (i==2) {
                    System.out.println("账户已被冻结");
                } else {
                    //将需要计算的变量用括号括起来就能实现和字符串的拼接
                    System.out.println("用户名或者密码有误，您还剩下"+(2-i)+"次机会。");
                }
            }
        }

    }
}
